import json


"""
好了，这些东西留着以后再写吧
2020年7月27日16:29:27
"""
"""
{
        "username": "河南共青团",
        "date": "2020-06-15",
        "text": "山东冠县女子被人顶替上大学：我就想知道她是怎么拿到我的通知书的。调查进行中，愿能还给她迟到的真相！#顶替他人上大学女子成绩低于分数线243分#@人民日报",
        "fabulous": "7,890次观看 · 28天前",
        "link": "https://weibo.com/tv/show/1034:4516095399231501?from=old_pc_videoshow",
        "reply_num": 2,
        "reply": [
            {
                "username": "的卢雨 ",
                "date": "2020-6-15",
                "text": "我也想知道呀",
                "fabulous": "1",
                "link": "",
                "reply_num": 0,
                "reply": []
            },
            {
                "username": "徐医在线拔牙 ",
                "date": "2020-6-15",
                "text": "山东最近老多事儿了，害",
                "fabulous": "1",
                "link": "",
                "reply_num": 0,
                "reply": []
            }
        ]
    }
"""


# 将数字格式化
def form_time(in_time: str):
    l = in_time.split('-')
    return "%04d-%02d-%02d" % (int(l[0]), int(l[1]), int(l[2]))


def formed_time_to_int(in_formed_time: str):
    l = in_formed_time.split('-')
    return int("%04d%02d%02d" % (int(l[0]), int(l[1]), int(l[2])))



def a_file_proc(a_file: list) :

    return a_file

# 把文件读成对象，然后把对象处理后返回
def merge(in_list: list, out_put_file_name_str: str):
    r = [[out_put_file_name_str], []]

    for filename in in_list:
        r[0].append(filename)
        r[1].append(json.load(open(filename, 'r', encoding='utf-8')))

    a_file_index: int = 0
    while a_file_index < len(in_list):
        r[1][a_file_index].remove(r[1][a_file_index][-1])
        r[1][a_file_index] = a_file_proc(r[1][a_file_index])
        a_file_index+=1


    """
    name_index = 1
    all_index = 1
    reply_index = 1
    for big_key in r[1]:
        big_key = list(big_key)
        big_key.remove(big_key[-1])  # 移除最后一个说明性字典
        print("正在排序...")
        big_key.sort(key=lambda x: formed_time_to_int(x['date']))
        # 遍历关键字
        
        for a_wb in big_key:
            a_wb = dict(a_wb)
            # 遍历 每一个微博
            a_wb['id'] = "%s%05d%05d" % (formed_time_to_int(a_wb['date']), all_index, 0)
            a_wb['sorce_file'] = in_list[name_index - 1]
            print(a_wb['id'])
            reply_index = 1  # 回复索引
            for a_rep in a_wb['reply']:
                a_rep = dict(a_rep)
                # 遍历每一个回复
                a_rep['id'] = "%s%05d%05d" % (formed_time_to_int(a_rep['date']), all_index, reply_index)
                reply_index += 1
            all_index += 1
        name_index += 1"""


    return r
